<template>
  <div ref="navBar" class="navBox">
    <div class="nav" :class="{ active: nav_active }">
      <!-- 存放导航栏的所有 -->
      <div class="container">
        <div class="nav_menu">1111111111111111</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "NavBar",
  data() {
    return {
      nav_active: false,
      box: {},
    };
  },
  mounted() {
    this.fixNav();
  },

  methods: {
    fixNav() {
      let _this = this;
      _this.box = this.$refs.navBar;
      console.log(this.box);
      _this.box.addEventListener("scroll", () => {
        if (this.$refs.navBar.scrollTop > 100) {
          this.nav_active = true;
        } else {
          this.navBar = false;
        }
      });
    },
  },
};
</script>

<style>
.navBox {
  height: 100vh;
  overflow: auto;
  z-index: -999;
}

.nav {
  position: fixed;
  background-color: azure;
  top: 0;
  right: 0;
  left: 0;
  transition: all 0.3s ease-in-out;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  z-index: 999;
}

.nav .container {
  height: 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 0;
  transition: all 0.3s ease-in-out;
}

.nav.active .container {
  padding: 15px;
  background-color: #1d354b;
}
</style>
